package com.pro.service.imple;

import com.pro.mapper.JsUserDevelopmentMapper;
import com.pro.pojo.JsUserDevelopment;
import com.pro.pojo.JsonData;
import com.pro.service.JsUserDevelopmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ClassName:JsUserDevelopmentServiceImple
 * Package:com.pro.service.imple
 * Description:
 *
 * @Date:2021/11/14 15:00
 * @Author: ZPT
 */
@Service
public class JsUserDevelopmentServiceImple implements JsUserDevelopmentService {

    @Autowired(required = false)
    private JsUserDevelopmentMapper mapper;
    @Override
    public JsonData getUserDevelopmentTable(Integer userCode,Integer studyDate,Integer consumption) {
        List<JsUserDevelopmentMapper> table = mapper.getUserDevelopmentTable(userCode,studyDate,consumption);
        int count = count();
        return table!=null?JsonData.buildSuccess(table,count):JsonData.buildError("服务端错误");
    }

    @Override
    public int count() {
        return 0;
    }

    @Override
    public Integer updateType(Integer userId, Integer type) {
        return mapper.updateType(userId,type);
    }

    @Override
    public List<JsUserDevelopment> getSearchUserDevelopment(String nickname, String profession) {
        return mapper.getSearchUserDevelopment(nickname,profession);
    }

    @Override
    public JsUserDevelopment getinformation(Integer userId) {
        return mapper.getinformation(userId);
    }

    @Override
    public Boolean updateUserDevelop(JsUserDevelopment jsUserDevelopment) {
        jsUserDevelopment.setUpdateDate(new Date());
        Boolean aBoolean = mapper.updateUserDevelop(jsUserDevelopment);
        if (aBoolean){
            Boolean aBoolean1 = mapper.updateUserBefore(jsUserDevelopment);
            return aBoolean1;
        }
        return aBoolean;
    }

    @Override
    public Boolean updateUserBefore(JsUserDevelopment jsUserDevelopment) {
        return mapper.updateUserBefore(jsUserDevelopment);
    }

    @Override
    public Boolean addUserDevelop(JsUserDevelopment jsUserDevelopment) {
        jsUserDevelopment.setCreateDate(new Date());
        return mapper.addUserDevelop(jsUserDevelopment);
    }
}
